package app.backend.controller;

import app.backend.common.CommonResult;
import app.backend.entity.BizAnnouncement;
import app.backend.service.BizAnnouncementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 通知公告表 控制器
 *
 * @author 程开磊
 * @date  2025/09/06 14:44
 */
@Slf4j
@RestController
@RequestMapping("/announcement")
@Tag(name = "通知公告管理", description = "通知公告相关接口")
public class BizAnnouncementController {

    @Resource
    private BizAnnouncementService bizAnnouncementService;

    /**
     * 获取开启状态的通知公告列表，按排序字段升序排序
     *
     * @return 通知公告列表
     */
    @GetMapping("/list")
    @Operation(summary = "获取通知公告列表", description = "获取开启状态的通知公告列表，按排序字段升序排序")
    public CommonResult<List<BizAnnouncement>> getAnnouncementList() {
        List<BizAnnouncement> announcementList = bizAnnouncementService.getEnabledAnnouncements();
        return CommonResult.data(announcementList);
    }

    @GetMapping("/info")
    @Operation(summary = "获取通知公告详情", description = "获取通知公告详情")
    public CommonResult<BizAnnouncement> getAnnouncement(@RequestParam("id") String id) {
        BizAnnouncement announcement = bizAnnouncementService.getById(id);
        return CommonResult.data(announcement);
    }
}
